#include "Utils.h"
#include "ListNode.h"
#include <iostream>
#include <vector>

ListNode* Utils::generateListByArray(std::vector<int> v) {
	if (v.size() == 0) {
		return NULL;
	}
	ListNode* head = new ListNode(v[0]);
	ListNode* cur = head;
	for (int i = 1; i < v.size(); i++) {
		cur->next = new ListNode(v[i]);
		cur = cur->next;
	}

	return head;
}

void Utils::freeList(ListNode* list) {
	if (list == nullptr) {
		return;
	}

	while (list != nullptr) {
		ListNode* next = list->next;
		delete list;
		list = next;
	}
}

void Utils::printList(ListNode* list) {
	std::cout << "list = { ";
	while (list != nullptr) {
		std::cout << list->val;
		if (list->next != nullptr) {
			std::cout << ", ";
		}
		list = list->next;
	}
	std::cout << " }" << std::endl;
}

void Utils::printTreeList(TreeNode* root) {
	std::cout << "treeList = { ";
	
	std::cout << " }" << std::endl;
}